package com.example.service;

import io.minio.errors.*;
import io.minio.messages.Bucket;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * @author SongXuSheng
 * @description: minIo服务接口
 * @date 2022/8/18 21:15
 */
public interface MinIoService {
    /**
     * description: 判断bucket是否存在
     * @return: void
     * @param bucketName 桶名称
     * @author: songxusheng
     * @time: 2022/8/17 15:03
     */
    boolean bucketExists(String bucketName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException;

    /**
     * description: 创建bucket
     * @return: void
     * @param bucketName 桶名称
     * @author: songxusheng
     * @time: 2022/8/17 15:03
     */
    void createBucket(String bucketName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException;

    /**
     * description: 获取全部bucket
     * @return: void
     * @author: songxusheng
     * @time: 2022/8/17 15:03
     */
    List<Bucket> getAllBuckets() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException;

    /**
     * description: 上传文件并返回文件名称
     *
     * @param bucketName 桶名称
     * @param file MultipartFile文件流
     * @return: java.lang.String
     * @author: songxusheng
     * @time: 2021/8/25 10:44
     */
    String upload(MultipartFile file, String bucketName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException;

    /**
     * description: 获取文件url
     *
     * @param bucketName 桶名称
     * @param fileName 文件名称
     * @return: url 文件路径
     * @author: songxusheng
     * @time: 2021/8/25 10:44
     */
    String getFileUrl(String bucketName, String fileName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException;

    /**
     * description: 获取文件url并设置过期时间
     *
     * @param bucketName 桶名称
     * @param fileName 文件名称
     * @return: url 文件路径
     * @author: songxusheng
     * @time: 2021/8/25 10:44
     */
    String getFileUrl(String bucketName,String fileName, Integer expires) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException;


}
